home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 14639 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.8 KB  |  71 lines

  1. Path: HOPPER.ACM.ORG!news
  2. From: varnk@e62.diebold.com (Ken Varn)
  3. Newsgroups: comp.lang.c++
  4. Subject: Need help with strstream
  5. Date: 1 Apr 1996 13:39:05 GMT
  6. Organization: Diebold
  7. Message-ID: <4jom9q$an4@HOPPER.ACM.ORG>
  8. NNTP-Posting-Host: 199.218.232.47
  9. Mime-Version: 1.0
  10. Content-Type: Text/Plain; charset=US-ASCII
  11. X-Newsreader: WinVN 0.99.7
  12.  
  13.      Let me start out by saying that I am really new to C++.  I am trying to 
  14. use an object created from the strstream class in a template class that I am 
  15. creating.
  16.  
  17. i.e.
  18.  
  19. template <class DataType> LinkItem {
  20.  private:
  21.     HWND Window;
  22.     DataType Data;
  23.  
  24. public:
  25.     strstream Stream;
  26.  
  27. ....
  28. ....
  29.  
  30. }
  31.  
  32. I have member functions that will be used to transfer the Data to the Window 
  33. and vice versa as well as various other member functions for getting, 
  34. setting, etc..  The Window takes Text data only.  So I am using the strstram 
  35. class to allow me to convert the text data to DataType data and vice versa.  
  36. I want the strstream object to be a public data member so that users of this
  37. class can change the format of numeric values when they are transfered to 
  38. text format.
  39.  
  40. The documentation I have on strstream is a bit vague.
  41. I want the Stream object to create its processing buffer using dynamic 
  42. allocation.  I read that this will occur if it is not supplied with a buffer 
  43. at construction time.  How do I reset the strstream object to dynamically 
  44. allocate a new transfer beffer each time it is used?  How do I get the length 
  45. of the text that is stored in the buffer?  I am real worried about causing a 
  46. memory leak here, so I want to make sure that I do this right.
  47.  
  48. I am calling it in a member function like this:
  49.  
  50. void Transfer()
  51.  
  52. {
  53. char *Text;
  54. int Length;
  55.  
  56. // Need to reset Stream buffer here.
  57. Stream << Data;
  58.  
  59. // Need length of buffer here
  60. Text = new char[Length];
  61.  
  62. Stream >> Text;
  63.  
  64. // Store text to window
  65. ...
  66. ...
  67.  
  68. delete Text[];
  69. }
  70.  
  71.